<template>
  <div>
    <el-row>
      <el-col>
        <el-col>
          <el-form :inline="true" :model="formInline">
            <el-form-item>
              <el-input size="mini" v-model="formInline.num" placeholder="请输入设备编号"></el-input>
            </el-form-item>
            <el-form-item>
              <el-input size="mini" v-model="formInline.name" placeholder="请输入设备名称"></el-input>
            </el-form-item>
            <el-form-item>
              <el-select clearable size="mini" v-model="formInline.status" placeholder="请选择状态">
                <el-option label="启用" value="1"></el-option>
                <el-option label="禁用" value="0"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" size="mini" @click="search">查询</el-button>
            </el-form-item>
          </el-form>
        </el-col>
      </el-col>
    </el-row>
    <el-row>
      <!--<el-col :span="4">
        <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
      </el-col>-->
      <el-col :span="24">
        <el-table
                :data="tableData"
                size="mini"
                @selection-change="handleSelectionChange"
                border
                style="width: 100%">
          <el-table-column
                  align="center"
                  type="selection"
                  width="55">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="NUM"
                  label="设备编号">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="NAME"
                  label="设备名称">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="USERNAME"
                  width="100px"
                  label="操作人">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="SCRAPCAUSE"
                  label="报废原因">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="STATUS"
                  label="状态">
            <template slot-scope="scope">
              {{scope.row.STATUS ? '启用': '禁用'}}
            </template>
          </el-table-column>
          <el-table-column
                  width="170px"
                  align="center"
                  prop="STARTTIME"
                  label="操作日期">
            <template slot-scope="scope">
              {{new Date(scope.row.CREATETIME).toLocaleString()}}
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                background
                layout="total, sizes, prev, pager, next, jumper"
                :page-size="pagination.pageSize"
                :total="pagination.total"
                :page-sizes="[10, 20, 30, 50, 100]"
        >
        </el-pagination>
      </el-col>
    </el-row>
    <el-dialog title="维保记录" center :visible.sync="dialogFormVisible" width="60%">
      <el-row>
        <el-col :span="11">
          <el-form :model="form" :label-width="formLabelWidth">
            <el-form-item label="设备名称">
              <el-input size="mini" v-model="form.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="设备编号">
              <el-input size="mini" v-model="form.user" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="放置地">
              <el-input size="mini" v-model="form.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="入库时间">
              <el-date-picker
                      v-model="form.value"
                      size="mini"
                      type="date"
                      placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="购置时间">
              <el-date-picker
                      v-model="form.value"
                      size="mini"
                      type="date"
                      placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="贵重仪器">
              <el-radio-group v-model="form.resource" size="mini">
                <el-radio label="是"></el-radio>
                <el-radio label="否"></el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="低值易耗品">
              <el-radio-group v-model="form.resource" size="mini">
                <el-radio label="是"></el-radio>
                <el-radio label="否"></el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="仪器分类">
              <el-radio-group v-model="form.resource" size="mini">
                <el-radio label="竞赛用仪器"></el-radio>
                <el-radio label="教学类仪器"></el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="设备说明">
              <el-input size="mini" v-model="form.name" type="textarea"></el-input>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="11" offset="2">
          <div class="block">
            <el-timeline>
              <el-timeline-item timestamp="2018/4/12" placement="top">
                <el-card>
                  <h4>第一次维保</h4>
                  <p>维保描述：</p>
                  <el-image src="https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg"></el-image>
                </el-card>
              </el-timeline-item>
              <el-timeline-item timestamp="2018/4/3" placement="top">
                <el-card>
                  <h4>第二次维保</h4>
                  <p>维保描述：12121212121212</p>
                </el-card>
              </el-timeline-item>
              <el-timeline-item timestamp="2018/4/2" placement="top">
                <el-card>
                  <h4>第三次维保</h4>
                  <p>维保描述：</p>
                  <el-image src="https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg"></el-image>
                </el-card>
              </el-timeline-item>
            </el-timeline>
          </div>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="dialogFormVisible = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="dialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="维保信息" center :visible.sync="dialogFormVisible2" width="60%">
      <el-row>
        <el-col :span="11">
          <el-form :model="form" :label-width="formLabelWidth">
            <el-form-item label="开始日期">
              <input disabled size="mini" v-model="form.startTime"></input>
            </el-form-item>
            <el-form-item label="结束日期">
              <input disabled size="mini" v-model="form.endTime"></input>
            </el-form-item>
            <el-form-item label="维保内容">
              <el-input disabled size="mini" v-model="form.maintCause" type="textarea"></el-input>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="11" :offset="2">
          <div class="block">
            <el-timeline>
              <el-timeline-item
                      v-for="list in timeList"
                      :timestamp="new Date(list.CREATETIME).toLocaleString() + '-' + list.USERNAME + '-' + list.MSG"
                      placement="top">
              </el-timeline-item>
            </el-timeline>
          </div>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="dialogFormVisible2 = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: "scrapRecord",
    data() {
      return{
        dialogVisible: false,
        form: {},
        form2: {},
        dialogFormVisible: false,
        dialogFormVisible2: false,
        data: [{
          label: '同济科技职业学院',
          children: [{
            label: '校区1',
            children: [{
              label: '学院',
              children: [{
                label: "实训基地",
                children: [{
                  label: "实训室"
                }]
              }]
            }]
          }]
        }],
        defaultProps: {
          children: 'children',
          label: 'label'
        },
        pagination: {
          pageSize: 20,
          total: 1,
          pageNo: 1
        },
        formLabelWidth: '120px',
        formInline: {},
        tableData: [],
        btnDisabled: true,
        tableVal: [],
        dialogFormVisible3: false,
        timeList: []
      }
    },
    created() {
      this.getData(this.pagination.pageSize, this.pagination.pageNo);
    },
    methods: {
      search() {
        this.$post('/insrtument/findInstrument', {
          pageSize:this.pagination.pageSize,
          pageNo: 1,
          name: this.formInline.name,
          num: this.formInline.num,
          status: this.formInline.status
        }).then(res => {
          if(res.data.status != 1) {
            this.$message.error('条件输入错误，请检查');
            return;
          }
          this.pagination.total = res.data.data.total;
          this.tableData = res.data.data.dataList;
        })
      },
      getData(pageSize, pageNo) {
        this.$post('/insrtumentScrap/findInstrumentScrap', {pageSize, pageNo}).then(res => {
          this.tableData = res.data.data.dataList;
          this.pagination.total = res.data.data.total;
        })
      },
      view() {
        this.form.startTime = this.tableVal[0].STARTTIME;
        this.form.endTime = this.tableVal[0].ENDTIME;
        this.form.maintCause = this.tableVal[0].MAINTCAUSE;
        this.dialogFormVisible2 = true;
        let lifycycleType = '';
        if(this.tableVal[0].MAINTTYPE === 1) {
          lifycycleType = 5
        } else {
          lifycycleType = 4
        }
        this.$post('/insrtument/findInstrumentLifeCycle',
                {
                  instrumentId: this.tableVal[0].INSTRUMENTID,
                  lifycycleType:lifycycleType
                }
        ).then(res => {
          this.timeList = res.data.data.dataList;
        })
      },
      submit() {
        let arr = [];
        for(let i = 0; i < this.tableVal.length; i++) {
          arr.push(this.tableVal[i].ID);
        }
        this.form.instrumentId = arr.join();
        this.$post('/insrtumentMaint/addMaintTypeFor1', this.form).then(res => {
          if(res.data.status === 1) {
            this.$message.success(res.data.msg);
            this.dialogFormVisible2 = false
          } else {
            this.$message.error(res.data.msg)
          }
        })
      },
      submit2() {
        this.form2.instrumentId = this.tableVal[0].ID;
        this.$post('/insrtumentMaint/add', this.form2).then(res => {
          if(res.data.status === 1) {
            this.$message.success(res.data.msg);
            this.dialogFormVisible3 = false
          } else {
            this.$message.error(res.data.msg)
          }
        })
      },
      handleSizeChange(size) {
        this.pagination.pageSize = size;
        this.getData(size, this.pagination.pageNo);
      },
      handleCurrentChange(page) {
        this.pagination.pageNo = page;
        this.getData(this.pagination.pageSize, page);
      },
      handleSelectionChange(val) {
        if (val.length === 1) {
          this.btnDisabled = false;
        }else{
          this.btnDisabled = true;
        }
        this.tableVal = val;
      },
      handleNodeClick(data) {
        console.log(data);
      }
    }
  }
</script>

<style scoped lang="scss">
  .search{
    margin-bottom: 10px;
  }
  /deep/.el-select{
    width: 100%;
  }
  .addDev {
    /deep/.el-form-item__content {
      display: flex;
    }
  }
  /deep/.el-divider{
    background: #409eff;
  }
  /deep/.el-divider__text{
    font-size: 18px;
    color: #409eff;
  }
  /deep/.el-date-editor.el-input, .el-date-editor.el-input__inner {
    width: 100%
  }
  .dateStyle{
    /deep/.el-input__inner {
      padding-left: 30px !important;
    }
  }
</style>
